'use strict';

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _child_process = require('child_process');

var _npmWhich = require('npm-which');

var _npmWhich2 = _interopRequireDefault(_npmWhich);

var _debug2 = require('debug');

var _debug3 = _interopRequireDefault(_debug2);

var _utils = require('../utils');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

var debug = (0, _debug3.default)('build-tools:lint');
var which = (0, _npmWhich2.default)(__dirname);
var args = process.argv.slice(2);

// if `.eslintrc` found then use it instead built-in `eslintrc.js`
var config = !(0, _utils.fileExists)('.eslintrc') ? ['--config', _path2.default.join(__dirname, '../config/eslintrc.js')] : [];

// if `.eslintignore` found then use it instead built-in `eslintignore`
var ignore = !(0, _utils.fileExists)('.eslintignore') ? ['--ignore-path', _path2.default.join(__dirname, '../config/.eslintignore')] : [];

debug('Run eslint from ' + which.sync('eslint'));
debug('With config: ' + config.join(' '));
debug('With ignore: ' + ignore.join(' '));
debug('With other args: ' + args);

var result = (0, _child_process.spawnSync)(which.sync('eslint'), [].concat(config, ignore, _toConsumableArray(args)), {
  stdio: 'inherit',
  env: process.env
});

process.exit(result.status);